<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Mockery\Exception;

class Vip extends Model
{
    public $timestamps = false;
    protected $table = "jkbl_vip";


    //圈子权限
    const CIRCLE_STATUS_OFF = 0;
    const CIRCLE_STATUS_ON = 1;

    static $CircleStatusDisplay = [
        self::CIRCLE_STATUS_OFF => '无权查看',
        self::CIRCLE_STATUS_ON => '有权查看',
    ];

    //能否查看用户详情
    const SCANUSER_OFF = 0;
    const SCANUSER_ON = 1;

    static $ScanuserDisplay = [
        self::SCANUSER_OFF => '无权限',
        self::SCANUSER_ON => '有权限',
    ];

    //咨询状态
    const CONSULTTYPE_PIC = 1;
    const CONSULTTYPE_VOICE = 2;
    const CONSULTTYPE_VIDEO = 3;

    static $ConsultTypeDisplay = [
        self::CONSULTTYPE_PIC => '图文',
        self::CONSULTTYPE_VOICE => '语音',
        self::CONSULTTYPE_VIDEO => '视频',
    ];

    //VIP状态
    const STATUS_OFF = 0;
    const STATUS_ON = 1;

    static $StatusDisplay = [
        self::STATUS_OFF => '停用',
        self::STATUS_ON => '启用',
    ];


    const QUNSEND_NO = 0;
    const QUNSEND_YES = 1;

    static $QunsendDisplay = [
        self::QUNSEND_NO=>'无权限',
        self::QUNSEND_YES=>'有权限',
    ];


    /**
     * 添加VIP级别
     * @return array
     */
    static function StoreVipPublish()
    {
        try {
            $vip = new Vip();
            foreach (['weight', 'title', 'timelimt', 'circle', 'docnum', 'shownum', 'scanuser', 'coupon', 'consulttype', 'keeptime', 'status', 'qunsend'] as $item) {
                $vip->$item = request()->$item;
            }
            $vip->createtime = time();
            if (!$vip->save()) {
                return error('保存失败');
            }
            return success('成功');
        } catch (Exception $exception) {
            logger($exception);
            return error('出错了，请联系技术人员');
        }
    }


    /**
     * 修改VIP级别
     * @param $vip
     * @return array
     */
    static function StoreVipModify($vip)
    {
        try {
            foreach (['weight', 'title', 'timelimt', 'circle', 'docnum', 'shownum', 'scanuser', 'coupon', 'consulttype', 'keeptime', 'status','qunsend'] as $item) {
                if (request()->has($item)) {
                    $vip->$item = request()->$item;
                }
            }
            if (!$vip->save()) {
                return error('保存失败');
            }
            return success('成功');
        } catch (Exception $exception) {
            logger($exception);
            return error('出错了，请联系技术人员');
        }
    }
}
